home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / What's New? / Development Kits / Apple Game Sprockets DR1 / Examples / GlyphaIII / G3Main.c < prev    next >
Encoding:
Text File  |  1996-04-24  |  3.7 KB  |  126 lines  |  [TEXT/MPCC]

  1.  
  2. //============================================================================
  3. //----------------------------------------------------------------------------
  4. //                                Glypha III 1.0.1
  5. //                                by  Scheherazade
  6. //----------------------------------------------------------------------------
  7. //============================================================================
  8.  
  9. // Here is the "main" file for Glypha.  Here is where the game begins and ends.
  10. // Also included are the preference calls.
  11.  
  12. #include "G3Externs.h"
  13. #include <Sound.h>
  14.  
  15.  
  16. #define kPrefsVersion            0x0001
  17.  
  18.  
  19. void ReadInPrefs (void);
  20. void WriteOutPrefs (void);
  21. void main (void);
  22.  
  23.  
  24. prefsInfo    thePrefs;
  25. short        wasVolume;
  26.  
  27. extern    Boolean        quitting, playing, pausing, evenFrame;
  28. void UpdateMainWindow (void);
  29.  
  30.  
  31. //==============================================================  Functions
  32. //--------------------------------------------------------------  ReadInPrefs
  33.  
  34. //    This function loads up the preferences.  If the preferences 
  35. //    aren't found, all settings are set to their defaults.
  36.  
  37. void ReadInPrefs (void)
  38. {
  39.     short        i;
  40.                             // Call LoadPrefs() function - returns TRUE if it worked.
  41.     if (LoadPrefs(&thePrefs, kPrefsVersion))
  42.         SetSoundVol(thePrefs.wasVolume);
  43.     else                    // If LoadPrefs() failed, set defaults.
  44.     {
  45.         thePrefs.prefVersion = kPrefsVersion;                // version of prefs
  46.         thePrefs.filler = 0;                                // just padding
  47.         PasStringCopy("\pYour Name", thePrefs.highName);    // last highscores name
  48.         for (i = 0; i < 10; i++)                            // loop through scores
  49.         {
  50.             PasStringCopy("\pNemo", thePrefs.highNames[i]);    // put "Nemo" in name
  51.             thePrefs.highScores[i] = 0L;                    // set highscore to 0
  52.             thePrefs.highLevel[i] = 0;                        // level attained = 0
  53.         }
  54.         GetSoundVol(&thePrefs.wasVolume);
  55.     }
  56.                             // Get sound volume so we can restore it.
  57.     GetSoundVol(&wasVolume);
  58. }
  59.  
  60. //--------------------------------------------------------------  WriteOutPrefs
  61.  
  62. //    This function writes out the preferences to disk and restores 
  63. //    the sound volume to its setting before Glypha was launched.
  64.  
  65. void WriteOutPrefs (void)
  66. {
  67.     if (!SavePrefs(&thePrefs, kPrefsVersion))
  68.         SysBeep(1);
  69.     SetSoundVol(wasVolume);
  70. }
  71.  
  72. //--------------------------------------------------------------  main
  73.  
  74. //    This is the main function.  Every C program has one of these.
  75. //    First it initializes our program and then falls into a loop
  76. //    until the user chooses to quit.  At that point, it cleans up
  77. //    and exits.
  78.  
  79. void main (void)
  80. {
  81.     long        tickWait;
  82.     OSStatus    theError;
  83.     
  84.     ToolBoxInit();            // Call function that initializes the ToolBox managers.
  85.     CheckEnvirons();        // Check the Mac we're on to see if we can run.
  86.     OpenMainWindow();        // Open up the main window - it will fill the monitor.
  87.     InitVariables();        // Initialize Glypha's variables.
  88.     InitSound();            // Create sound channels and load up sounds.
  89.     InitMenubar();            // Set up the game's menubar.
  90.     ReadInPrefs();            // Load up the preferences.
  91.  
  92. #if GENERATINGPOWERPC
  93.     UpdateMainWindow();
  94.  
  95.     theError = FadeDisplayGamma( NULL, kSmoothFadeIn, NULL );
  96.     if( theError )
  97.         RedAlert("\pUnable to unfade the display!");
  98.     
  99. #endif
  100.  
  101.     do                        // Here begins the main loop.
  102.     {
  103.         HandleEvent();        // Check for events.
  104.         if ((playing) && (!pausing))
  105.             PlayGame();        // If user began game, drop in game loop. (play mode)
  106.         else                // If no game, animate the screen. (idle mode)
  107.         {
  108.             tickWait = TickCount() + 2L;
  109.             evenFrame = !evenFrame;
  110.             DrawTorches();    // Flicker torches.
  111.             CopyAllRects();    // Refresh screen.
  112.             do                // Wait for 2 Ticks to pass to keep fast Macs at bay.
  113.             {
  114.             }
  115.             while (TickCount() < tickWait);
  116.         }
  117.     }
  118.     while (!quitting);
  119.     
  120.     KillSound();            // Dispose of sound channels.
  121.     ShutItDown();            // Dispose of other structures.
  122.     WriteOutPrefs();        // Save preferences to disk.
  123.  
  124. }
  125.  
  126.